<?php

/**
 * @copyright 2011
 * @version $Id$
 * @access public
 * @author Oriotiori

 */

class Admin_Model_Facade_Products{

	/**
	 * @param array $to: Array de datos a guardar.
	 * @return int $lastid
	 */
	public function addProduct($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->addProduct($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * @param array $to: Array de datos a guardar.
	 * @return boolean
	 */
	public function updateProductById($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->updateProductById($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}




	/**
	 * @param array $to: Array de datos a guardar.
	 * @return array $data
	 */
	public function AddImageDB($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->AddImageDB($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * Obtiene los productos
	 * @param int $id : catid
	 * @param int $status: status of products.
	 * @return array $data
	 */
	public function getProductsByCategory($id=0, $status='all')
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getProductsByCategory($id, $status);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}


	/**
	 * Obtiene los productos
	 * @param int $id : catid
	 * @param int $status: status of products.
	 * @return array $data
	 */
	public function getProductsExcludeFeatured($status='all')
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getProductsExcludeFeatured($status);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * Obtiene los productos destacados
	 * @return array $data
	 */
	public function getFeatured($id=0, $status='all')
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getFeatured($id, $status);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * Obtiene todos los productos
	 * return $data array
	 */
	public function getTotalProducts()
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getTotalProducts();
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * Obtiene producto por id
	 * @param int $id
	 * @return array $data
	 */
	public function getProductById($id=0)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getProductById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * elimina imagen product
	 * @param int $id
	 * @return array $data
	 */
	public function deleteImageProduct($id=0)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->deleteImageProduct($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}



	/**
	 * elimina  product
	 * @param int $id
	 * @return array $data
	 */
	public function deleteProductById($id=0)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->deleteProductById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	
	/**
	 * obtiene imagenes por producto
	 * @param int $id
	 * @return array $data
	 */
	public function getAllImagesByProduct($id=0)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->getAllImagesByProduct($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

	/**
	 * Crea Thumb
	 * @param array $resource: Array de datos
	 * @return boolean $data
	 */
	public function CreateThumb($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		$facadeConfigs= new Admin_Model_Facade_Configs();
		$configs=$facadeConfigs->getConfigs();
		try{
			$to['Width']=$configs['Product_Thumb_Width'];
			$to['Height']=$configs['Product_Thumb_Height'];
			$to['Path']='Real';
			$to['Directory']='product';
			$to['NewPath']='Thumb';
			$to['mode']='Thumb';
			$data = $TBD_Resource->CreateThumb($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}


	/**
	 * Crea MiniThumb
	 * @param array $resource: Array de datos
	 * @return boolean $data
	 */
	public function CreateMiniThumb($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		$facadeConfigs= new Admin_Model_Facade_Configs();
		$configs=$facadeConfigs->getConfigs();

		try{
			$to['Width']=$configs['Product_Mini_Thumb_Width'];
			$to['Height']=$configs['Product_Mini_Thumb_Height'];
			$to['Path']='Real';
			$to['Directory']='product';
			$to['NewPath']='Mini_Thumb';
			$to['mode']='Mini_Thumb';
			$data = $TBD_Resource->CreateThumb($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}


	/**
	 * Crea Medium
	 * @param array $resource: Array de datos
	 * @return boolean $data
	 */
	public function CreateMedium($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		$facadeConfigs= new Admin_Model_Facade_Configs();
		$configs=$facadeConfigs->getConfigs();

		try{
			$to['Width']=$configs['Product_Medium_Width'];
			$to['Height']=$configs['Product_Medium_Height'];
			$to['Path']='Real';
			$to['Directory']='product';
			$to['NewPath']='Medium';
			$to['mode']='Medium';
			$data = $TBD_Resource->CreateThumb($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}



	/**
	 * @param array $to: Array de datos a guardar.
	 * @return int $lastid
	 */
	public function addProductFeatured($to)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->addProductFeatured($to);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}


	/**
	 * elimina  product
	 * @param int $id
	 * @return array $data
	 */
	public function deleteProductFeaturedById($id=0)
	{
		$TBD_Resource = new Admin_Model_Products();
		try{
			$data = $TBD_Resource->deleteProductFeaturedById($id);
			return $data;
		}catch(Exception $e)
		{
			$error=array($e->getFile(), 'Exception: '.$e->getMessage());
			$ExceptionHandler= new Default_Model_ExceptionHandler();
			$ExceptionHandler->saveErrors($error);
		}
		return false;
	}

}
